﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace FrmHotel
{
    public partial class FrmXzFangjian : Form
    {
        public FrmXzFangjian()
        {
            InitializeComponent();
        }
        public int id;//接收的房间号
       
        private void button2_MouseEnter(object sender, EventArgs e)
        {
            this.button2.BackColor = Color.FromArgb(249, 102, 34);
        }

        private void button2_MouseLeave(object sender, EventArgs e)
        {
            this.button2.BackColor = Color.FromArgb(69, 94, 100);
        }

        private void button3_MouseLeave(object sender, EventArgs e)
        {
            this.button3.BackColor = Color.FromArgb(69, 94, 100);
        }

        private void button3_MouseEnter(object sender, EventArgs e)
        {
            this.button3.BackColor = Color.FromArgb(249, 102, 34);
        }

        private void FrmXzFangjian_Load(object sender, EventArgs e)
        {
            BindCombobox();
            BoinListView();
        }
        public void BindCombobox()
        {
            //string sql = "select * from Room";
            //DataTable dt = DBHelper.SelectForTable(sql);
            ////添加一个选项
            //DataRow dr = dt.NewRow();
            //dr["RoomId"] = 0;
            //dr["RoomName"] = "全部";
            ////把新行放入表格中
            //dt.Rows.InsertAt(dr, 0);

            //this.comboBox1.DisplayMember = "RoomName";
            //this.comboBox1.ValueMember = "RoomId";
            //this.comboBox1.DataSource = dt;
        }
        public void BoinListView()
        {
            this.listView1.Items.Clear();
            string ss = string.Format("select RmRoom from RoomInfo r where RmId={0}", id);
            int re = Convert.ToInt32(DBHelper.SelectOne(ss));
            string sql = string.Format("select r.RmId,o.RoomName,o.RoomMoney,s.StName from RoomInfo r,Room o,RmState s  where s.StId=r.RmState and r.RmRoom=o.RoomId and r.RmRoom={0} and r.RmState=1 ", re);
            string hao = this.textBox1.Text; //获取输入的房间号
            if (!string.IsNullOrEmpty(hao))
            {
                sql = sql + string.Format(" and RmId like '%{0}%'", hao);
            }
            //int RoomId = Convert.ToInt32(this.comboBox1.SelectedValue);
            //if (RoomId != 0)
            //{
            //    sql = sql + " and r.RmRoom=" + RoomId;
            //}
            SqlDataReader reader = DBHelper.SelectMore(sql);
            while (reader.Read())
            {
                ListViewItem item = new ListViewItem(reader["RmId"].ToString());
                item.SubItems.Add(reader["RoomName"].ToString());
                item.SubItems.Add(reader["RoomMoney"].ToString());
                item.SubItems.Add(reader["StName"].ToString());
                    item.BackColor = Color.FromArgb(91, 188, 32);
                listView1.Items.Add(item);
            }
            reader.Close();
        }

        private void button3_Click(object sender, EventArgs e)
        {
            this.Close();
        }
        public int ih;
        private void button2_Click(object sender, EventArgs e)
        {
            if (this.listView1.SelectedItems.Count <= 0)
            {
                MessageBox.Show("请至少选择一间房间入住！", "提示信息！");
                return;
            }
             ListViewItem item = this.listView1.SelectedItems[0];
            int id = Convert.ToInt32(item.Text);
            Class1.fangjian = id;
            FrmGengHuan fg = new FrmGengHuan();
            ih = id;
            this.Close();
            
        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {
            BoinListView();
        }

        private void comboBox1_TextChanged(object sender, EventArgs e)
        {
            BoinListView();
        }
    }
}
